
    getOrder();

    function getOrder() {
        $.ajax({
            type: "get",
            url: Url + "address",
            async: false,
            timeout : 20000,
            beforeSend: function (xhr) {
                showDiv()
                xhr.setRequestHeader("token", tokenk);
            },
            success: function (data) {
                hiddenDiv()
                console.log(data);
                if (data.length == 0) {
                    $(".discount-main-no").css("display", "block")
                }
                var str = '';
                var abc;
                $(data).each(function (k, v) {
                    if (v['is_default']) {
                        abc = '<div class="main-1-ok" style="display:inline">默认</div>'
                    } else {
                        abc = '';
                    }
                    str += '<div class="address-list-main" _isDefault="' + v['is_default'] + '" _id="' + v['uaddres_id'] + '">'
                        + '<div class="address-list-main-show">'
                        + '<div class="address-list-main-1">'
                        + '<div class="main-1-name">' + v['uaddres_name'] + '</div>' +
                        abc
                        + '</div>'
                        + '<div class="address-list-main-2">'
                        + '<div class="main-1-tell">' + v['uaddres_mobile'] + '</div>'
                        + '<div  class="main-1-add">' + v['uaddres_province'] + '' + v['uaddres_city'] + '' + v['uaddres_county'] + '' + v['uaddres_detail'] + '</div>'
                        + '</div>'
                        + '<div class="address-list-main-3">'
                        + '<a href="add.html?id=' + v['uaddres_id'] + '"><img class="address-list-edit" src="/static/index/img/edit.png"/></a>'
                        + '</div>'
                        + '</div>'
                        + '<div class="delete-button">'
                        + '<img class="delete-img" _id="' + v['uaddres_id'] + '" src="/static/index/img/icon-delete.png"/>'
                        + '</div>'
                        + '</div>'
                })
                $("#address-list").html(str)
            },
            error: function (request, status, err) {
                failure(status)
            }
        });
        if (document.referrer.indexOf("checkout") != -1) {
            storage.setItem('referrer', document.referrer)
        }
    }

    $(".delete-button").click(function () {
        $(this).parents(".address-list-main").remove();
        var _id = $(this).children().attr("_id");
        console.log(_id)
        $.ajax({
            type: "get",
            url: Url + 'deleAddr/' + _id,
            async: false,
            timeout : 20000,
            beforeSend: function (xhr) {
                showDiv()
            },
            success: function (data) {
                hiddenDiv()
                taostr("删除成功", 1000)
            },
            error: function (request, status, err) {
                failure(status)
            }
        })
    });

    $(".address-list-main").click(function () {
        var referrer = document.referrer;
        if (referrer.indexOf("checkout") != -1) {
            var id = $(this).attr('_id');
            $.ajax({
                type: "get",
                url: Url + "addressDefault/" + id,
                async: false,
                timeout : 20000,
                beforeSend: function (xhr) {

                    xhr.setRequestHeader("token", tokenk);
                },
                success: function (data) {
                    hiddenDiv()
                    if (data) {
                        location.href = referrer;
                    }
                },
                error: function (request, status, err) {
                    failure(status)
                }
            });


        }
    })


    var endX;
    $("#main").on('touchstart', '.address-list-main-show', function (e) {
        var touch = e.originalEvent.targetTouches[0];
        startX = touch.pageX;
        console.log(startX)
    })
    $("#main").on('touchmove', '.address-list-main-show', function (e) {

        var touch = e.originalEvent.targetTouches[0];
        endX = (startX - touch.pageX);
        if (endX > 0 && endX <= 140) {
            $(this).css("left", -endX / 100 + 'rem')
        } else if (endX < 0) {
            $(this).css("left", 0 + 'rem')
        }
    })
    $("#main").on('touchend', '.address-list-main-show', function (e) {
        $(".carts-item").css("left", 0 + 'rem')
        console.log(endX)
        if (endX >= 70) {
            $(this).css("left", '-1.4rem')
        }
    })
